package com.yanqu.road.dao.impl.servercenter;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.servercenter.ChannelVersion;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 渠道版本信息
 */
public class ChannelVersionDaoImpl extends TempDao {

	public List<ChannelVersion> getChannelVersionList() {
		ResultSet rs = null;
		CallableStatement call = null;
		String sql = "select * from t_s_channel_version";
		List<ChannelVersion> dataList = new ArrayList<>();
		try {
			getDb().setConnName(DbNameStrategy.getServerDb());
			call = getDb().getConnection().prepareCall(sql);
			rs = call.executeQuery();
			while (rs.next()) {
				ChannelVersion data = new ChannelVersion();
				data.setChannelId(rs.getInt("channelId"));
				data.setPhonePlatform(rs.getInt("phonePlatform"));
				String value = rs.getString("clientVersion");
				if(!StringUtils.isNullOrEmpty(value)){
					data.setClientVersion(value);
				}
				data.setReview(rs.getBoolean("isReview"));
				data.setLastRelease(rs.getBoolean("isLastRelease"));
				data.setWhiteLastRelease(rs.getBoolean("isWhiteLastRelease"));
				dataList.add(data);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			getDb().closeConnection(call, rs);
		}
		return dataList;
	}
}
